package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.FirewallStrategy;
import com.ruoyi.experiment.service.IFirewallStrategyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 防火墙策略Controller
 * 
 * @author 邓鑫
 * @date 2023-07-28
 */
@RestController
@RequestMapping("/experiment/strategy")
public class FirewallStrategyController extends BaseController
{
    @Autowired
    private IFirewallStrategyService firewallStrategyService;

    /**
     * 查询防火墙策略列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(FirewallStrategy firewallStrategy)
    {
        startPage();
        List<FirewallStrategy> list = firewallStrategyService.selectFirewallStrategyList(firewallStrategy);
        return getDataTable(list);
    }

    /**
     * 导出防火墙策略列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:export')")
    @Log(title = "防火墙策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirewallStrategy firewallStrategy)
    {
        List<FirewallStrategy> list = firewallStrategyService.selectFirewallStrategyList(firewallStrategy);
        ExcelUtil<FirewallStrategy> util = new ExcelUtil<FirewallStrategy>(FirewallStrategy.class);
        util.exportExcel(response, list, "防火墙策略数据");
    }

    /**
     * 获取防火墙策略详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:query')")
    @GetMapping(value = "/{firewallStrategyId}")
    public AjaxResult getInfo(@PathVariable("firewallStrategyId") Long firewallStrategyId)
    {
        return success(firewallStrategyService.selectFirewallStrategyByFirewallStrategyId(firewallStrategyId));
    }

    /**
     * 新增防火墙策略
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:add')")
    @Log(title = "防火墙策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirewallStrategy firewallStrategy)
    {
        return toAjax(firewallStrategyService.insertFirewallStrategy(firewallStrategy));
    }

    /**
     * 修改防火墙策略
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:edit')")
    @Log(title = "防火墙策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirewallStrategy firewallStrategy)
    {
        return toAjax(firewallStrategyService.updateFirewallStrategy(firewallStrategy));
    }

    /**
     * 删除防火墙策略
     */
    @PreAuthorize("@ss.hasPermi('experiment:strategy:remove')")
    @Log(title = "防火墙策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{firewallStrategyIds}")
    public AjaxResult remove(@PathVariable Long[] firewallStrategyIds)
    {
        return toAjax(firewallStrategyService.deleteFirewallStrategyByFirewallStrategyIds(firewallStrategyIds));
    }

    /**
     * 不带参数获取策略列表
     */
    @GetMapping("/getList")
    public AjaxResult getList()
    {
        return AjaxResult.success(firewallStrategyService.getList());
    }
}
